package cn.ysnk.generateCode;


public enum ColumnEnum {

	VARCHAR("String"), DATETIME("Date"), DOUBLE("Double"),INT("Integer"),
	TEXT("String"),
	TINYINT("Integer")
	;
	private String value;
	private ColumnEnum(String value){
		this.value = value;
	}
	
	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public static ColumnEnum switch2ColumnEnum(String value){
		String eqValue = value.indexOf("(")>0?value.substring(0, value.indexOf("(")).toUpperCase():value.toUpperCase();
		ColumnEnum[] enums = ColumnEnum.values();
		for(ColumnEnum e:enums){
			if(e.name().equals(eqValue)){
				return e;
			}
		}
		return VARCHAR;
	}
	
	@Override
	public String toString() {
		return value;
	}
	public String generateInitValue() {
		String result = "\"\"";
		if(value.equals(DATETIME.toString())){
			result = "null";
		}else if(value.equals(DOUBLE.toString())){
			result = "0";
		}else if(value.equals(INT.toString())){
			result = "0";
		}
		return result;
	}
	public String generateFormValidator(){
		String result = "";
		if(value.equals(DATETIME.toString())){
			result = ",custom[date]";
		}else if(value.equals(DOUBLE.toString())){
			result = ",custom[number]";
		}else if(value.equals(INT.toString())){
			result = ",custom[integer]";
		}
		return result;
	}
	
	public String jfinalMethodGet(){
		String result = value;
		if(value.equals(VARCHAR.toString())){
			result = "Str";
		}else if(value.equals(INT.toString())){
			result = "Int";
		}
		return result;
	}
}
